package com.smartcruise.util.network.netUtils;

import com.google.gson.Gson;

import java.io.IOException;

import okhttp3.ResponseBody;

/**
 * Created by FengChaoQun
 * on 2018/2/5 0005
 * 网络请求返回的数据实体
 */

public class Result {

    private int code;//返回码

    private String message;//返回信息描叙

    private String data;//返回数据

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public static <T> Result create(T response) throws IOException {
        if (response instanceof ResponseBody) {
            Gson gson = new Gson();
            return gson.fromJson(((ResponseBody) response).string(), Result.class);
        } else {
            return null;
        }
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data='" + data + '\'' +
                '}';
    }
}
